%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: analyzeButtonTiming.m
% Co: The Neurosciences Institute
% Author: Richard G. Martin
% Purpose: Analyze APE-X button presses during matching trials.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function trial_time_list_ms = analyzeButtonTiming(button_data, phase_start_msec, phase_end_msec , trial_duration_msec, start_time_msec, end_time_msec)

%To Do: very specific function, so update script to incorporate
% phase_end_msec, start/end_time_msec

num_recordings = length(button_data)
test_start_indices = find(mod(button_data(:,1), trial_duration_msec) == phase_start_msec)
recording_step_ms = 25
num_testing_steps = (trial_duration_msec-phase_start_msec)/recording_step_ms
num_match_trials = length(test_start_indices)
trial_time_list_ms = ones(num_match_trials,1)*(trial_duration_msec-phase_start_msec)
for i=1:num_match_trials
    start_time = button_data(test_start_indices(i),1)
    for j=1:num_testing_steps
        if button_data(test_start_indices(i)+j,2) > 0
            trial_time_list_ms(i) = button_data(test_start_indices(i)+j,1) - start_time
            break
        end  
    end
end

%reshape data for specific Shepard Plot
%{
null_value = 2000; 
null_block = null_value*ones(4,4);
block_times = reshape(trial_time_list_ms,4,8)';
mirJ_times = block_times(1:4,:);
J_times = block_times(5:8,:);
mirJ_times = [mirJ_times null_block];
J_times = [null_block J_times];
all_times = [mirJ_times; J_times];
trial_time_list_ms = reshape(all_times',1,64);
%}
%return modified trial_time_list_ms modifed for plotShepard function